/**
 * PHOSIDE: PHosphorylation Site IDentification Engine.
 * Copyright 2009 Digital Biology Lab, University of Missouri.
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version. <p/> This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more
 * details.
 */

package phoside.io.fasta;

import java.io.IOException;

import java.util.Set;

import phoside.Proteins;
import phoside.PhosphoProteins;

/**
 *
 * @author gjj
 */
public class PhosphoWriterToFastaWithSitesInHeader extends FastaProteinsWriterToFile {

    public PhosphoWriterToFastaWithSitesInHeader(String fasta)
            throws IOException {
        super(fasta);
    }

    public PhosphoWriterToFastaWithSitesInHeader(String fasta, int aaPerLine)
            throws IOException {
        super(fasta, aaPerLine);
    }

    @Override
    protected String formatHeader(final Proteins data, final String acc) {
        if (! (data instanceof PhosphoProteins)) {
            throw new IllegalArgumentException();
        }
        
        StringBuilder ret = new StringBuilder(500);
        ret.append(super.formatHeader(data, acc));
        Set<Integer> sites = ((PhosphoProteins)data).getSites(acc);
        if (sites!=null && sites.size()>0) {
            ret.append("@SITE_START@");
            for (int site : sites) {
                ret.append(site+1);
                ret.append(";");
            }

            int n = ret.length();
            ret.replace(n-1, n, "@SITE_END@");
        }

        return ret.toString();
    }
    
}
